package com.wgf.controller;

import com.wgf.service.ChatAssistant;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.loader.FileSystemDocumentLoader;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class RAGController
{
    @Resource
    InMemoryEmbeddingStore<TextSegment> embeddingStore;

    @Resource
    ChatAssistant chatAssistant;

    // http://localhost:9113/rag/add
    @GetMapping(value = "/rag/add")
    public String testAdd()
    {
        Document document = FileSystemDocumentLoader.loadDocument("F:\\shangguigu\\Java面试资料\\Java基础常见面试题之简答题.pdf");//从文件系统加载文档

        //存储嵌入: 使用 EmbeddingStoreIngestor 存储嵌入向量
        EmbeddingStoreIngestor.ingest(document, embeddingStore);//将文档内容处理并存储到嵌入存储中

        String result = chatAssistant.chat("综合说下final的作用？");//使用聊天助手回答问题

        System.out.println(result);

        return result;
    }
}